package svc.elib.db;

import java.util.LinkedList;

/**
 * Information related to one paper
 * 
 * @author svc
 * @date 6.6.2012
 */
public class Paper {

	private String id;
	private String lang;
	private String journal;
	private int year;
	private LinkedList<Author> authors =
		new LinkedList<Author>();
	
	public Paper(String id, String lang, String journal, int year) {
		this.id = id;
		this.lang = lang;
		this.journal = journal;
		this.year = year;
	}
	
	public void addAuthor(Author a) {
		authors.add(a);
	}
	
	public String getId() { return id; }
	public String getLang() { return lang; }
	public String getJournal() { return journal; }
	public int getYear() { return year; }
	
	public LinkedList<Author> getAuthors() {
		return authors;
	}
	
	public boolean singleAuthor() {
		return authors.size() == 0;
	}

	public String getInfo() {
		StringBuilder sb = new StringBuilder();
		sb.append(id + ", " + lang + ", " + journal + ", " + year + ": ");
		for (int i = 0; i < authors.size(); i++) {
			sb.append(authors.get(i).getName() + " ");
		}
		return sb.toString();
	}

	public void mustBeRemovedAuthor(Author a) {
		boolean ok = authors.remove(a);
		if (!ok) {
			System.out.println("Error, mustBeRemovedAuthor, author " + a.getInfo() + " not found");
		}
	}

	public boolean isAuthor(Author a) {
		for (int i = 0; i < authors.size(); i++) {
			if (authors.get(i) == a)
				return true;
		}
		
		return false;
	}

	public void setAuthors(LinkedList<Author> newAuthors) {
		this.authors = newAuthors;
	}
}
